package com.heima.tlias.controller;

import com.heima.tlias.controller.request.LoginRequest;
import com.heima.tlias.controller.response.UserInfoVo;
import com.heima.tlias.service.LoginService;
import com.heima.tlias.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/login")
@RequiredArgsConstructor
public class LoginController {

    private final LoginService loginService;

    /***
     * 用户登录接口
     * @param request
     * @return
     */
    @PostMapping
    public Result<UserInfoVo> login(@RequestBody LoginRequest request) {
        UserInfoVo userInfoVo = loginService.login(request);
        if (userInfoVo==null){
            return Result.error("用户名或密码错误");
        }

        return Result.success(userInfoVo);
    }
}
